package com.dstation.service;

import com.dstation.dao.SubscriptionPackageInfoMapper;
import com.dstation.domain.SubscriptionPackageInfo;
import com.dstation.service.interf.ISubscriptionPackageService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.List;

/**
 * @author Eastward
 * @date 2022/5/8 - 21:42
 */
@Service
public class SubscriptionPackageServiceImpl implements ISubscriptionPackageService {

    @Resource
    private SubscriptionPackageInfoMapper subscriptionPackageInfoMapper;

    @Override
    public List<SubscriptionPackageInfo> findAllSubscriptionPackages() {
        return subscriptionPackageInfoMapper.selectAllSubscriptionPackages();
    }

    @Override
    public Boolean addSubscriptionPackage(BigDecimal subPackPrice, String subPackDescription, int subPackType) {
        SubscriptionPackageInfo subscriptionPackageInfo = new SubscriptionPackageInfo();
        subscriptionPackageInfo.setSubPackDescription(subPackDescription);
        subscriptionPackageInfo.setSubPackPrice(subPackPrice);
        subscriptionPackageInfo.setSubPackType(subPackType);
        Timestamp createDate = new Timestamp(System.currentTimeMillis());
        subscriptionPackageInfo.setCreateDate(createDate);
        return subscriptionPackageInfoMapper.insertSubscriptionPackage(subscriptionPackageInfo);
    }

    @Override
    public Boolean alterSubscriptionPackage(Long subPackId, BigDecimal subPackPrice, String subPackDescription, int subPackType) {
        SubscriptionPackageInfo subscriptionPackageInfo = new SubscriptionPackageInfo();
        subscriptionPackageInfo.setSubPackId(subPackId);
        subscriptionPackageInfo.setSubPackDescription(subPackDescription);
        subscriptionPackageInfo.setSubPackPrice(subPackPrice);
        subscriptionPackageInfo.setSubPackType(subPackType);
        Timestamp createDate = new Timestamp(System.currentTimeMillis());
        subscriptionPackageInfo.setCreateDate(createDate);
        return subscriptionPackageInfoMapper.updateSubscriptionPackage(subscriptionPackageInfo);
    }

    @Override
    public Boolean dropSubscriptionPackage(Long subPackId) {
        return subscriptionPackageInfoMapper.deletSubscriptionPackagee(subPackId);
    }

    @Override
    public List<SubscriptionPackageInfo> findAllSubscriptionPackagesByType(int subPackType) {
        return subscriptionPackageInfoMapper.selectAllSubscriptionPackagesByType(subPackType);
    }

    @Override
    public SubscriptionPackageInfo findSubscriptionPackageBySubPackId(Integer subPackId) {
        return subscriptionPackageInfoMapper.selectSubscriptionPackageBySubPackId(subPackId);
    }

}
